package inutan.match;

import org.ricks.boot.AbstractBootstrap;
import org.ricks.common.ModularContext;
import org.ricks.common.conf.RicksPropertiesLoader;
import org.ricks.common.event.EventBus;
import org.ricks.net.NetContext;
import org.ricks.orm.OrmContext;
import org.ricks.protocol.Protocol;
import org.ricks.protocol.ProtocolManager;

import java.util.Set;
import java.util.stream.Collectors;

public class MatchBootstrap extends AbstractBootstrap {

    @Override
    protected void onStart() {
        ModularContext.me().scan(Set.of("inutan.match"));
        RicksPropertiesLoader.loadingProperties();
        Set<Class<?>> classes = ModularContext.me().projectClasses();
        Set<Class<?>> protocolClasses = classes.stream().filter(c -> c.isAnnotationPresent(Protocol.class)).collect(Collectors.toSet());
        ProtocolManager.initProtocolAuto(protocolClasses);
        EventBus.me().init(); //初始化事件机制
        NetContext.me().init();
    }

    @Override
    protected void onStop() {
        EventBus.me().shutdown();
    }
}
